//
//  SimNavTitleView.m
//
//  Created by LiuXubin on 15/7/24.
//

#import "SimNavTitleView.h"
#import "UIView+SimAdditions.h"

SimImpValue(kSimNavTitleViewTitleColor, UIColor *)
SimImpValue(kSimNavTitleViewTitleFont, UIFont *)

SimImpValue(kSimNavTitleViewDetailColor, UIColor *)
SimImpValue(kSimNavTitleViewDetailFont, UIFont *)


@interface SimNavTitleView ()
{
}

@end

@implementation SimNavTitleView

- (id)initWithTitle:(NSString *)titleStr detailText:(NSString *)detailText
{
    self = [super initWithFrame:CGRectZero];
    if (self) {
        CGFloat width = 0, height = 0;
        
        _titleLb = [[UILabel alloc] init];
        _titleLb.lineBreakMode = NSLineBreakByTruncatingMiddle;
        _titleLb.font = SimValue(kSimNavTitleViewTitleFont, [UIFont boldSystemFontOfSize:15]);
        _titleLb.textColor = SimValue(kSimNavTitleViewTitleColor, [UIColor whiteColor]);
        _titleLb.backgroundColor = [UIColor clearColor];
        _titleLb.text = titleStr;
        [_titleLb sizeToFit];
        [self addSubview:_titleLb];
        width = MAX(_titleLb.width, width);
        height = _titleLb.height+1;
        

        _detailLb = [[UILabel alloc] init];
        _detailLb.font =  SimValue(kSimNavTitleViewDetailFont, [UIFont boldSystemFontOfSize:10]);
        _detailLb.textColor = SimValue(kSimNavTitleViewDetailColor, HEXRGBCOLOR(0xc8ebdd));
        _detailLb.backgroundColor = [UIColor clearColor];
        _detailLb.text = detailText;
        [_detailLb sizeToFit];
        [self addSubview:_detailLb];
        height += _detailLb.height;
        width =  MAX(_detailLb.width, width);
        
        self.size = CGSizeMake(width, height);
        _titleLb.centerX = width/2;
        _detailLb.bottom = height;
        _detailLb.centerX = width/2;
    }
    
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    if (_titleLb.width > self.width) {
        _titleLb.width = self.width;
        _titleLb.centerX = self.width/2;
    }
    
    if (_detailLb.width > self.width) {
        _detailLb.width = self.width;
        _detailLb.centerX = self.width/2;
    }
}

@end
